//
//  DataBase.m
//  city
//
//  Created by Apple on 2017/6/16.
//  Copyright © 2017年 闪电极送. All rights reserved.
//

#import "DataBase.h"
#import <FMDB.h>


static DataBase *_DBCtl = nil;

@interface DataBase()<NSCopying,NSMutableCopying>{
    FMDatabase  *_db;
    
}
@end
@implementation DataBase
+(instancetype)sharedDataBase{
    
    if (_DBCtl == nil) {
        
        _DBCtl = [[DataBase alloc] init];
        
        [_DBCtl initDataBase];
        
    }
    
    return _DBCtl;
    
}

+(instancetype)allocWithZone:(struct _NSZone *)zone{
    
    if (_DBCtl == nil) {
        
        _DBCtl = [super allocWithZone:zone];
        
    }
    
    return _DBCtl;
    
}

-(id)copy{
    
    return self;
    
}

-(id)mutableCopy{
    
    return self;
    
}

-(id)copyWithZone:(NSZone *)zone{
    
    return self;
    
}

-(id)mutableCopyWithZone:(NSZone *)zone{
    
    return self;
    
}


-(void)initDataBase{
      NSString *filePath = [[NSBundle mainBundle] pathForResource:@"areaNewDB" ofType:@"db"];
    
    // 实例化FMDataBase对象
    
    _db = [FMDatabase databaseWithPath:filePath];
    
    
}

- (NSMutableArray *)getAllCity{
    [_db open];
    
    NSMutableArray *dataArray = [[NSMutableArray alloc] init];
    FMResultSet *res = [FMResultSet new];
    res = [_db executeQuery:@"SELECT * FROM city"];
    
    while ([res next]) {
        CityName *city = [[CityName alloc] init];
        //person.cityID = [res stringForColumn:@"cityID"] ;
        city.cityname = [res stringForColumn:@"city"];
        
        [dataArray addObject:city.cityname];
        
    }
    
    [_db close];
   // NSLog(@"%@",dataArray);
    
    
    
    return dataArray;
    
    
}


@end
